{extend name="/base/base" /}
{block name="content"}
    <form class="layui-form layui-form-pane" enctype="multipart/form-data" >
        <div class="layui-form-item">
            <label class="layui-form-label">栏目名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入栏目名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属栏目</label>
            <div class="layui-input-block">
                <select name="pid" lay-verify="required">
                    <option value="0">顶级栏目</option>
                    {foreach $sort as $item}
                        <option value="{$item['id']}">{$item['name']}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
{/block}

{block name="js"}
    <script>
        //Demo
        layui.use('form', function(){
            var form = layui.form;
            var $ = layui.jquery;

            //监听提交
            form.on('submit(formDemo)', function(data){
                $.ajax({
                    url : "{:url('addHandle')}",
                    type : "POST",
                    // contentType: "application/json;charset=utf-8", // 上传内容的格式
                    data : data.field,
                    dataType : "json", // 返回的数据格式
                    success : function(data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1});
                        } else {
                            layer.msg(data.msg, {icon: 2});
                        }
                    },
                    error:function(data){
                        layer.msg(data.msg, {icon: 2});
                    }
                })
                return false;
            });
        });
    </script>
{/block}